package com.yndsoft.jc.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.yndsoft.jc.ui.memberpage.Session;
import com.yndsoft.jc.ui.net.HttpUtil;
import com.yndsoft.jc.utils.LogUtils;
import com.yndsoft.jc.utils.StatusBarCompat;

import butterknife.ButterKnife;


/**
 * Fragment基类
 *
 * @author liaiguo
 */
public abstract class BaseFragment extends Fragment {
    protected Context context;
    protected HttpUtil mHttpUtil;
    protected Session mSession;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        LogUtils.i(getFragmentName() + " onAttach()");
        context = activity;
        mSession = Session.get(getActivity());
        mHttpUtil = HttpUtil.getInstance();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarCompat.translucentStatusBar2(getActivity());
        LogUtils.i(getFragmentName() + " onCreate()");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        LogUtils.i(getFragmentName() + " onCreateView()");
        View view = inflater.inflate(getContentResouceId(), container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    /**
     * layout Res Id
     */
    public abstract int getContentResouceId();

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        LogUtils.i(getFragmentName() + " onViewCreated()");
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        LogUtils.i(getFragmentName() + " onActivityCreated()");
    }

    @Override
    public void onStart() {
        super.onStart();
        LogUtils.i(getFragmentName() + " onStart()");
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtils.i(getFragmentName() + " onResume()");
    }

    @Override
    public void onPause() {
        super.onPause();
        LogUtils.i(getFragmentName() + " onPause()");
    }

    @Override
    public void onStop() {
        super.onStop();
        LogUtils.i(getFragmentName() + " onStop()");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        LogUtils.i(getFragmentName() + " onDestroyView()");
        ButterKnife.unbind(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        LogUtils.i(getFragmentName() + " onDestroy()");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        LogUtils.i(getFragmentName() + " onDetach()");
    }

    /**
     * fragment name
     */
    public abstract String getFragmentName();


}
